package cn.com.ss.customer.generate.code.java;

import cn.com.ss.customer.generate.domain.Method;
import cn.com.ss.customer.generate.domain.TableColumnInfo;
import cn.com.ss.customer.generate.domain.TableInfo;
import cn.com.ss.customer.generate.util.PropertiesLoader;

/**
 * @author chenshijie
 * @title
 * @email chensj@winning.com.cm
 * @package cn.com.ss.customer.generate.code.java
 * @date 2018-05-25 21:55
 */
public class CommentGenerator {

    private static boolean suppressAllComments = Boolean.valueOf(PropertiesLoader.getProperty("config.comment"));

//    public void addModelClassComment(TopLevelClass topLevelClass,
//                                     IntrospectedTable introspectedTable) {
//        if (suppressAllComments) {
//            return;
//        }
//
//        topLevelClass.addJavaDocLine("/**"); //$NON-NLS-1$
//
//        String remarks = introspectedTable.getRemarks();
//        if (addRemarkComments && StringUtility.stringHasValue(remarks)) {
//            topLevelClass.addJavaDocLine(" * Database Table Remarks:"); //$NON-NLS-1$
//            String[] remarkLines = remarks.split(System.getProperty("line.separator"));  //$NON-NLS-1$
//            for (String remarkLine : remarkLines) {
//                topLevelClass.addJavaDocLine(" *   " + remarkLine);  //$NON-NLS-1$
//            }
//        }
//        topLevelClass.addJavaDocLine(" *"); //$NON-NLS-1$
//
//        topLevelClass
//                .addJavaDocLine(" * This class was generated by MyBatis Generator."); //$NON-NLS-1$
//
//        StringBuilder sb = new StringBuilder();
//        sb.append(" * This class corresponds to the database table "); //$NON-NLS-1$
//        sb.append(introspectedTable.getFullyQualifiedTable());
//        topLevelClass.addJavaDocLine(sb.toString());
//
//        addJavadocTag(topLevelClass, true);
//
//        topLevelClass.addJavaDocLine(" */"); //$NON-NLS-1$
//    }

    public static String addFieldComment(TableInfo introspectedTable,
                                TableColumnInfo introspectedColumn) {
        if (!suppressAllComments) {
            StringBuilder sb = new StringBuilder();
            sb.append("/**"); //$NON-NLS-1$
            sb.append(" * 数据库表名:"+introspectedTable.getTableName());
            sb.append(" * 数据库字段:"+introspectedColumn.getActualColumnName());
            sb.append(" * 备注:"+introspectedColumn.getRemarks());
            sb.append(" * 默认值："+introspectedColumn.getDefaultValue() == null ? "" :introspectedColumn.getDefaultValue()); //$NON-NLS-1$
            sb.append(" */");
            return sb.toString();
        }
        return  null;

    }
    public  static void addGeneralMethodComment(Method method,
                                        TableInfo introspectedTable) {
        if (!suppressAllComments) {
            return;
        }

        StringBuilder sb = new StringBuilder();
        method.addJavaDocLine("/**"); //$NON-NLS-1$
        method.addJavaDocLine(" * This method was generated by MyBatis Generator."); //$NON-NLS-1$
        sb.append(" * This method corresponds to the database table "); //$NON-NLS-1$
        sb.append(introspectedTable.getTableName());
        method.addJavaDocLine(sb.toString());
        method.addJavaDocLine(" */"); //$NON-NLS-1$
    }

    public static  void addGetterComment(Method method,
                                 TableInfo introspectedTable,
                                 TableColumnInfo introspectedColumn) {
        if (!suppressAllComments) {
            return;
        }

        StringBuilder sb = new StringBuilder();

        method.addJavaDocLine("/**"); //$NON-NLS-1$
        method
                .addJavaDocLine(" * This method was generated by MyBatis Generator."); //$NON-NLS-1$

        sb.append(" * This method returns the value of the database column "); //$NON-NLS-1$
        sb.append(introspectedTable.getTableName());
        sb.append('.');
        sb.append(introspectedColumn.getActualColumnName());
        method.addJavaDocLine(sb.toString());
        method.addJavaDocLine(" *"); //$NON-NLS-1$
        sb.setLength(0);
        sb.append(" * @return the value of "); //$NON-NLS-1$
        sb.append(introspectedTable.getTableName());
        sb.append('.');
        sb.append(introspectedColumn.getActualColumnName());
        method.addJavaDocLine(sb.toString());
        method.addJavaDocLine(" */"); //$NON-NLS-1$
    }

    public static void addSetterComment(Method method,
                                 TableInfo introspectedTable,
                                 TableColumnInfo introspectedColumn) {
        if (!suppressAllComments) {
            return;
        }

        StringBuilder sb = new StringBuilder();

        method.addJavaDocLine("/**"); //$NON-NLS-1$
        method.addJavaDocLine(" * This method was generated by MyBatis Generator."); //$NON-NLS-1$
        sb.append(" * This method sets the value of the database column "); //$NON-NLS-1$
        sb.append(introspectedTable.getTableName());
        sb.append('.');
        sb.append(introspectedColumn.getActualColumnName());
        method.addJavaDocLine(sb.toString());
        method.addJavaDocLine(" *"); //$NON-NLS-1$
        sb.append(" * @param "); //$NON-NLS-1$
        sb.append(introspectedColumn.getDomainColumnName());
        sb.append(" the value for "); //$NON-NLS-1$
        sb.append(introspectedTable.getTableName());
        sb.append('.');
        sb.append(introspectedColumn.getActualColumnName());
        method.addJavaDocLine(sb.toString());
        method.addJavaDocLine(" */"); //$NON-NLS-1$
    }
}
